﻿Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.Management
Imports System.Management.Instrumentation
Imports System.Drawing
Imports System.Drawing.Drawing2D
Module CommFunction
    '用于获取自windows启动以来经历的时间长度（毫秒）
    <DllImport("kernel32", EntryPoint:="GetTickCount", SetLastError:=False, _
    CharSet:=CharSet.Auto, ExactSpelling:=False, _
    CallingConvention:=CallingConvention.StdCall)> _
        Public Function GetTickCount _
                      () As Integer
    End Function
    <Serializable()> _
    Public Structure frmTextEditData
        Public frmX As Integer
        Public frmY As Integer
        Public frmWidth As Integer
        Public frmHeight As Integer
        Public formWindowState As System.Windows.Forms.FormWindowState
        Public isShowStatus As Boolean
        Public isWordWrap As Boolean
        Public TextFont As Font
        Public TextColor As Color
    End Structure
    <Serializable()> _
    Public Structure CheckMode
        ''' <summary>
        ''' 校验码函数名
        ''' </summary>
        ''' <remarks></remarks>
        Dim CheckFunName As String
        ''' <summary>
        ''' 校验码名称
        ''' </summary>
        ''' <remarks></remarks>
        Dim CheckName As String
        ''' <summary>
        ''' 校验码位数
        ''' </summary>
        ''' <remarks></remarks>
        Dim CheckLength As Integer
        ''' <summary>
        ''' 校验码算法VBS源码
        ''' </summary>
        ''' <remarks></remarks>
        Dim CheckCode As String
        ''' <summary>
        ''' 校验方式说明
        ''' </summary>
        ''' <remarks></remarks>
        Dim CheckDescription As String
    End Structure
    <Serializable()> _
    Public Structure TabSaveData
        Dim StartNumberSelected As Integer
        Dim StartNumberText As String
        Dim FinishNumberText As String
        Dim StepString As String
        Dim LengthText As String
        Dim CheckModeSelected As Integer
        Dim Suffix As String
        Dim Prefix As String
        Dim InsertChar As String
        Dim InsertPosition As ArrayList
        Dim InsertCharAtPostion As ArrayList
        Dim Fixed As Boolean
        Dim BH As Boolean
        Dim 扩展信息1 As Object
        Dim 扩展信息2 As Object
    End Structure
    <Serializable()> _
    Public Structure SaveSetting
        Dim TabCount As Integer
        Dim SaveName As String
        Dim Data As List(Of TabSaveData)
        Dim 是否加黑线 As Boolean
        Dim 黑线位置 As Integer
        Dim 是否补号 As Boolean
        Dim 补号每行号码个数 As Integer
        Dim 每组行数 As Integer
    End Structure
    <Serializable()> _
    Public Structure SearchData
        ''' <summary>
        ''' 表名
        ''' </summary>
        ''' <remarks></remarks>
        Dim TableName As String
        ''' <summary>
        ''' 数据库名
        ''' </summary>
        ''' <remarks></remarks>
        Dim DataBaseName As String
        ''' <summary>
        ''' 搜索数据sql语句
        ''' </summary>
        ''' <remarks></remarks>
        Dim SearchSql As String
        ''' <summary>
        ''' 加载数据到datatable的sql语句
        ''' </summary>
        ''' <remarks></remarks>
        Dim DownLoadDataSql As String
        ''' <summary>
        ''' 填充主界面DataGridView数据表的VBS代码
        ''' </summary>
        ''' <remarks></remarks>
        Dim LoadDataVBS As String
        ''' <summary>
        ''' 加载显示描述Sql语句
        ''' </summary>
        ''' <remarks></remarks>
        Dim DescriptionSql As String
    End Structure

    <Serializable()> _
    Public Structure Save_DataStructure
        Dim LastSaveFilePath As String
        Dim DataBaseIP As String
        Dim DataBasePort As Integer
        Dim DataBaseUserName As String
        Dim DataBasePassword As String
        Dim DataBase As String
        Dim SearchTable As List(Of SearchData)
        Dim LastSearchTable As String
        Dim CheckNumberMode As List(Of CheckMode)
        Dim Setting As List(Of SaveSetting)
        Dim RegisterCode As String
        Dim EditFormData As frmTextEditData
        Dim DHLData As DHLDataStructure
    End Structure
    ''' <summary>
    ''' DHL箱号标签数据
    ''' </summary>
    ''' <remarks></remarks>
    ''' 
    <Serializable()> _
    Public Structure DHLDataStructure
        Public REGION As String
        Public Country As String
        Public RegionCoord As String
        Public Product As String
        Public Period As String
        Public PO_NO As String
        Public TO_NO As String
        Public 每箱号码数 As Integer
        Public 每盘总箱数 As Integer
        Public StartNO As String
        Public EndNo As String
        Public StartXH As Long
        Public StartPH As Long
    End Structure
    Public CheckData As New List(Of CheckMode)
    Public SaveData As New Save_DataStructure
    Public Sql As New SqlDataBase
    Public SearchResult As DataTable
    Public CurrentSearchData As SearchData
    Public CheckScript As New MSScriptControl.ScriptControl
    Public RegionAccess As Boolean = False
    Public frmSettingX As Single, frmSettingY As Single, MenuSkinRender As New MenuSkin
    Public SaveEditeHandle As New List(Of frm_TextEdit)
    Public Sub LoadCheckMode() '加载校验方式
        AddCheckMode("NoCheck", "", 0, "", "无校验方式")
        AddCheckMode("模七", "Mod7", 1, "", "模七校验方法：被校验数据除以7的余数。")
        AddCheckMode("模10", "getMod10", 1, "", "1、奇数位之和乘以3加上偶数位之和除以10的余数；" & vbCrLf & "2、当余数为0时则校验码为0；" & vbCrLf & "3.当余数不为0时校验码为10-余数；")
        AddCheckMode("模11", "ModEleven", 1, "", "模十一校验方法： " & vbCrLf & "1、只能对8位号码进行校验；" _
         & vbCrLf & "2、各位数据对应乘以86423597得到的和除以11的余数;" _
         & vbCrLf & "3、当余数为0时校验码为5，当余数为1时，校验码为0，余数其它校码为11-余数。")
        AddCheckMode("全一", "QuanYI", 1, "")
        AddCheckMode("顺丰", "SunFeng", 1, "")
        AddCheckMode("九福州", "getAlemtat", 1, "")
        AddCheckMode("信丰1位", "XinFeng1245", 1, "")
        AddCheckMode("信丰3位", "XinFeng3", 3, "")
        AddCheckMode("百世物流", "BaiShiTong3", 1, "")
        AddCheckMode("港中能达", "GangZhong", 1, "")
        AddCheckMode("Only_Vector", "Only_Vector", 1, "")
        AddCheckMode("WaybillNoList", "getWaybillNoList", 1, "")
        AddCheckMode("港中能达（无限制）", "getGangzhongNengDa", 1, "")
        AddCheckMode("晋越", "GetJinYue", 1, "", "前十位数之和减去第十一位数，所得结果除以9的余数即为校验码。")
        AddCheckMode("中铁", "getCheckZhongtian", 1, "", "中铁校验方式：" & vbCrLf & "  1.代码位置序号" & vbCrLf & "  代码位置序号是指不包括校验码在内的，由右至左的顺序号（校验码的代码位置序号为1）。" & vbCrLf & "  2.计算步骤" _
                     & vbCrLf & "  a.从代码位置序号2开始，所有偶数位的数字代码求和。" & vbCrLf & "  b.将步骤a的和乘以3，再加上18。" & vbCrLf & "  c.从代码位置序号3开始，所有奇数的数字代码求和，再乘以2，再减去3." _
                     & vbCrLf & "  d.将步骤b与c的结果相加，再乘以7。" & vbCrLf & "  e.用大于或等于步骤d所得结果且位13最小整数倍的数减去步骤d所得结果，其差的个位即为所求校验码的值。")

        AddCheckMode("黄马甲", "Gethuangmajia", 2, "", "号码总长度12位，前十位为流水号，后两位为检验位校验码计算方式:" _
& vbCrLf & "    1.分别取前五位数, 得到str1, str2, str3, str4, str5, 再将得到的结果求和得到sum1" _
& vbCrLf & "    2.从第六位数开始去五位数, 得到str6, str7, str8, str9, str10, 将得到结果求和得到sum2" _
& vbCrLf & "    3.分别将sum1和sum2除以7取余数得到结果, Q1, Q2。" _
& vbCrLf & "    4.将Q1和Q2以字符形式连接即是校验码")
        AddCheckMode("深圳石化", "getSHCheck", 2, "")
        AddCheckMode("城市应急", "CityExpress", 1, "", "前十二位流水号，各个位数对应乘以2,4,3,6,7,4,4,9,4,6,5,4，所得结果的和的个位数，X即为校验码")
        AddCheckMode("三菱空调", "getSanlinkongtiao", 1, "", "流水号每位字符对应的Ascii码的和除以10的余数")
        CheckScript.Reset()
        CheckScript.Language = "VBScript"
        Try '从本地文件加载脚本源码
            If SaveData.CheckNumberMode IsNot Nothing Then
                For i = 0 To SaveData.CheckNumberMode.Count - 1
                    Try
                        'MsgBox(SaveData.CheckNumberMode.Item(i).CheckName)
                        If CheckScript.Modules.Count <= 0 Then CheckScript.Modules.Add("CheckMode")
                        CheckScript.AddCode(SaveData.CheckNumberMode.Item(i).CheckCode)
                        AddCheckMode(SaveData.CheckNumberMode(i).CheckName, SaveData.CheckNumberMode(i).CheckFunName, SaveData.CheckNumberMode(i).CheckLength, SaveData.CheckNumberMode(i).CheckCode, SaveData.CheckNumberMode(i).CheckDescription)
                    Catch ex As Exception
                        ' MsgBox(ex.Message)
                    End Try
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub AddCheckMode(ByVal sCheckName As String, ByVal sFunName As String, ByVal CheckLength As Integer, ByVal CheckCode As String)
        Dim TmpCheck As New CheckMode
        With TmpCheck
            .CheckName = sCheckName
            .CheckFunName = sFunName
            .CheckCode = CheckCode
            .CheckLength = CheckLength
        End With
        CheckData.Add(TmpCheck)
    End Sub
    Public Sub AddCheckMode(ByVal sCheckName As String, ByVal sFunName As String, ByVal CheckLength As Integer, ByVal CheckCode As String, ByVal CheckDescription As String)
        Dim TmpCheck As New CheckMode
        With TmpCheck
            .CheckName = sCheckName
            .CheckFunName = sFunName
            .CheckCode = CheckCode
            .CheckLength = CheckLength
            .CheckDescription = CheckDescription
        End With
        CheckData.Add(TmpCheck)
    End Sub
    Public Function getTmpPath() As String
        Dim tmp As String = System.Reflection.Assembly.GetExecutingAssembly.Location  'System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
        Dim a As Integer = tmp.LastIndexOf("\")
        tmp = tmp.Substring(0, a)
        If Strings.Right(tmp, 1) <> "\" Then tmp = tmp & "\"
        Return tmp
    End Function
    Public Function getAddFileName(ByVal FileName As String) As String
        Dim a As Integer, c As Integer
        Dim b As Integer, noType As String, TypeStr As String
        Dim Value As String, LeftP As String
        a = FileName.LastIndexOf(".")
        c = FileName.LastIndexOf("\")
        If c < a Then
            noType = FileName.Substring(0, a)
            TypeStr = FileName.Substring(a)
        Else
            noType = FileName
            TypeStr = ""
        End If
        If Right(noType, 1) = ")" Then
            b = InStrRev(noType, "(")
            Value = Mid(noType, b + 1, noType.Length - b - 1)
            LeftP = Left(noType, b - 1)
            If IsNumeric(Value) Then
                Value = Val(Value) + 1
                Return LeftP & "(" & Value & ")" & TypeStr
            Else
                Return noType & "(1)" & TypeStr
            End If
        Else
            Return noType & "(1)" & TypeStr
        End If
    End Function
    Public Function FormatTickCount(ByVal Tim As Integer) As String
        Dim ms, k, hm, se As Integer
        Dim ts As Integer
        k = Tim
        hm = k / 3600000
        ms = (k - 3600000 * hm) / 60000
        se = (k - 3600000 * hm - 60000 * ms) / 1000
        ts = se
        If se < 0 Then
            ts = 30 + se
        Else
            ts = 30 + se
        End If
        FormatTickCount = Format(hm, "00") & ":" & Format(ms, "00") & ":" & Format(ts, "00")
    End Function
    ''' <summary>
    ''' 取函数或过程名，只对单个函数或过程进行取值，只支持Basic代码
    ''' </summary>
    ''' <param name="mCode">函数代码</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getVbsSubOrFunName(ByVal mCode As String) As String
        On Error Resume Next
        Dim SaveCode() As String
        Const FunHead As String = "function "
        Const SubHead As String = "sub "
        Dim tmp As String = "", F As Integer, S As Integer
        SaveCode = mCode.Split(vbCrLf)
        For i = 0 To SaveCode.Length - 1
            tmp = SaveCode(i)
            F = tmp.ToUpper.IndexOf(FunHead.ToUpper)
            S = tmp.ToUpper.IndexOf(SubHead.ToUpper)
            If F >= 0 Or S >= 0 Then
                If F >= 0 Then
                    Dim a As Integer = tmp.LastIndexOf("(")
                    Dim TmpName As String
                    If a > F Then
                        If a - F - FunHead.Length > 0 Then
                            TmpName = tmp.Substring(F + FunHead.Length, a - F - FunHead.Length)
                            Return TmpName.Trim
                        End If
                    End If
                End If
                If S >= 0 Then
                    Dim a As Integer = tmp.ToUpper.LastIndexOf("(")
                    Dim TmpName As String
                    If a - S - SubHead.Length > 0 Then
                        TmpName = tmp.Substring(S + SubHead.Length, a - S - SubHead.Length)
                        Return TmpName.Trim
                    End If
                End If
            End If
        Next
        Return ""
    End Function
    Public Sub ChangeButtonColor(ByVal obj As gdButton)
        With obj
            .AttachSkin = True
            .Radius = 2
            .DownBorder = Color.FromArgb(64, 0, 0)
            .DownColor = New Color() {Color.FromArgb(150, 150, 150), Color.FromArgb(180, 180, 180), Color.FromArgb(200, 200, 200), Color.FromArgb(230, 230, 230)}
            .FocusBorder = Color.FromArgb(180, 180, 10)
            .FocusColor = New Color() {Color.FromArgb(250, 240, 201), Color.FromArgb(249, 238, 193), Color.FromArgb(251, 240, 177), Color.FromArgb(247, 237, 159), Color.FromArgb(247, 237, 139), Color.FromArgb(247, 237, 119)}
            .NormalBorder = Color.FromArgb(180, 180, 180)
            .NormalColor = New Color() {Color.FromArgb(255, 247, 247, 247), Color.FromArgb(255, 237, 237, 237), Color.FromArgb(255, 217, 217, 217), Color.FromArgb(255, 207, 207, 207), Color.FromArgb(255, 217, 217, 217)} '{Color.White, Color.FromArgb(240, 240, 240), Color.FromArgb(224, 224, 224), Color.White}
        End With
    End Sub
    Public Function GetControlType(ByVal Obj As Control) As String
        Dim TpName As String = Obj.GetType().ToString
        Return TpName
    End Function
    Public Function GetControlType(ByVal Obj As Object) As String
        Dim TpName As String = Obj.GetType().ToString
        Return TpName
    End Function

    Public Sub ChangeButtonFromFrm(ByVal frm As Object)
        Dim tp As String = ""
        On Error Resume Next
        For Each itemObj As Control In frm.Controls
            tp = GetControlType(itemObj)
            If tp = "喷码数据生成工具.gdButton" Then
                ChangeButtonColor(itemObj)
            End If
        Next
        'MsgBox(tp)
    End Sub
    Public Function GetMac() As String
        Try

            Dim stringMAC As String = ""
            Dim stringIP As String = ""

            Dim query As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
            Dim queryCollection As ManagementObjectCollection = query.Get
            For Each mo As ManagementObject In queryCollection
                If CBool(mo("IPEnabled").ToString) = True Then
                    stringMAC += mo("MACAddress").ToString()
                End If
            Next
            Return stringMAC
        Catch ex As Exception
        End Try
        Return String.Empty
    End Function
    Public Function CaculateRegistration(ByVal MACAdress As String) As String
        Dim Mac As String = MACAdress
        Dim SplitMac() As String = Strings.Split(Mac, ":")
        Dim Result As String = ""
        For i = 0 To SplitMac.Length - 1
            If Result <> "" Then
                Result = Result & "-" & fenduanjisuan(SplitMac(i))
            Else
                Result = fenduanjisuan(SplitMac(i))
            End If
        Next
        Return Result
    End Function
    Private Function fenduanjisuan(ByVal value As String) As String
        If value.Length <> 2 Then value = "0" & value
        Dim Str1 As String, Str2 As String, Str1Asc As Integer, Str2Asc As Integer
        Dim Tmp As String, TmpAsc As Integer, Result1 As Integer, Result2 As Integer, Result As String
        Const Code As String = "ssjj22020"
        Str1 = value.Substring(0, 1) : Str2 = value.Substring(1, 1)
        Str1Asc = Asc(Str1) : Str2Asc = Asc(Str2)
        Result1 = Str1Asc : Result2 = Str2Asc
        For i = 0 To Code.Length - 1
            Tmp = Code.Substring(i, 1)
            TmpAsc = Asc(Tmp)
            Result1 = Result1 Xor TmpAsc
            Result2 = Result2 Xor TmpAsc
        Next
        Result = Result1 & Result2
        If Result.Length < 4 Then Result = Strings.Format(Val(Result) Mod 7, "00") & Strings.Format(Val(Result) \ 7, "00")
        Return Result
    End Function
    Public Sub Registration(Optional ByVal ShowInput As Boolean = False)
        Dim gMAC As String = GetMac()
        Dim CaculateRegionCode As String = ""
        Dim InputT As String, DesObj As New DES
        If gMAC.Length > 17 Then gMAC = gMAC.Substring(0, 17)
        CaculateRegionCode = CaculateRegistration(gMAC)
        Try
            If ShowInput Then GoTo RegisterLine
            If String.IsNullOrEmpty(SaveData.RegisterCode) Then SaveData.RegisterCode = My.Computer.Registry.GetValue("CreateData_Tengen", "RegionCode", "null")
            If SaveData.RegisterCode = "" Then
RegisterLine:
                InputT = RemedyCode.ShowInput(Form1, "输入注册码", "", False) 'InputBox("输入注册码", "注册")
                If InputT = CaculateRegionCode Then
                    RegionAccess = True
                    SaveData.RegisterCode = DesObj.Encrypt(InputT.Replace("-", ":"), "sj235689")
                    Form1.SaveSetting()
                    Form1.ChangeRegionObjEnabled()
                    ' My.Computer.Registry.SetValue("CreateData_Tengen", "RegionCode", SaveData.RegisterCode)
                    MsgBox("注册成功！", MsgBoxStyle.Information, "提示")
                Else
                    RegionAccess = False
                    If String.IsNullOrEmpty(InputT) Then InputT = "ErrorCode"
                    SaveData.RegisterCode = InputT
                    Form1.ChangeRegionObjEnabled()
                    Form1.SaveSetting()
                    'My.Computer.Registry.CurrentUser.("CreateData_Tengen", "RegionCode", InputT)
                    MsgBox("错误的注册码，请输入正确的注册码！", MsgBoxStyle.Critical, "注册失败")
                End If
            Else
                Dim rT As String = SaveData.RegisterCode
                If CaculateRegionCode.ToUpper = DesObj.Decrypt(SaveData.RegisterCode, "sj235689").Replace(":", "-") Then
                    RegionAccess = True
                    Form1.ChangeRegionObjEnabled()
                Else
                    ' GoTo RegisterLine
                    RegionAccess = False
                    Form1.ChangeRegionObjEnabled()
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            RegionAccess = False
            Form1.ChangeRegionObjEnabled()
        End Try
    End Sub
    Public Function getOnlyPath(ByVal FileName As String) As String
        Dim a As Integer = FileName.LastIndexOf("\")
        If a >= 2 Then
            Return FileName.Substring(0, a) & "\"
        Else
            Return ""
        End If
    End Function
    ''' <summary>
    ''' 格式化数值为字符串，不足长度以0站位"
    ''' </summary>
    ''' <param name="value">欲格式化数据</param>
    ''' <param name="length">数据长度</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function FormatByLength(ByVal value As Long, ByVal length As Integer)
        Const TypeStr As String = "00000000000000000000000000000000000000000"
        If TypeStr.Length < length Then Throw New Exception("所需数据长度超出软件限制！")
        Dim result As String = Strings.Format(value, Strings.Left(TypeStr, length))
        Return result
    End Function
#Region "创建快捷方式"
    Public Sub CreateShotCut()
        Try
            Dim DeskTop As String = GetDeskTop()
            Dim FileName As String = System.Reflection.Assembly.GetExecutingAssembly.Location
            Dim wsh As Object = CreateObject("WScript.Shell")
            Dim Lnk As Object = wsh.createshortcut(DeskTop & "\喷码数据生成工具.lnk")
            With Lnk
                .arguments = "/?"
                .description = "条形码喷码数据生成工具"
                .targetpath = FileName
                .workingdirectory = Application.StartupPath
                .windowstyle = 1
                .save()
            End With
            MsgBox("快捷方式创建成功！", MsgBoxStyle.Information, "提示")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "错误")
        End Try
    End Sub
    ''' <summary>
    ''' 获取计算机用户名
    ''' </summary>
    ''' <returns></returns>
    Public Function APIGetUserName() As String
        Dim str1 As String = ""
        Dim a As Integer
        str1 = System.Security.Principal.WindowsIdentity.GetCurrent.Name
        a = str1.LastIndexOf("\")
        str1 = str1.Substring(0, a)
        Return str1
    End Function
    ''' <summary>
    ''' 获取计算机名
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function APIGetComputerName() As String
        Dim str1 As String = ""
        Dim a As Integer
        str1 = System.Security.Principal.WindowsIdentity.GetCurrent.Name
        a = str1.LastIndexOf("\")
        str1 = str1.Substring(a + 1)
        Return str1
    End Function
    ''' <summary>
    ''' 获取程序所在路径
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getAppPath(ByVal FileName As String) As String
        Dim a As Integer = FileName.LastIndexOf("\")
        Dim Result As String
        If a > 0 Then
            Result = FileName.Substring(0, a)
            Return Result
        Else
            Return ""
        End If
    End Function
    Public Function getAppPath() As String
        Dim FileName As String = System.Reflection.Assembly.GetExecutingAssembly.Location.ToString
        Dim a As Integer = FileName.LastIndexOf("\")
        Dim Result As String
        If a > 0 Then
            Result = FileName.Substring(0, a)
            Return Result
        Else
            Return ""
        End If
    End Function
    ''' <summary>
    ''' 获取程序Exe文件名
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getOnlyName(ByVal FileName As String) As String
        Dim a As Integer = FileName.LastIndexOf("\")
        Dim b As Integer = FileName.LastIndexOf(".")
        Dim Result As String
        If b > a And a > 0 And b - a - 1 Then
            Result = FileName.Substring(a + 1, b - a - 1)
            Return Result
        Else
            Return ""
        End If
    End Function
    Public Function getOnlyName() As String
        Dim FileName As String = System.Reflection.Assembly.GetExecutingAssembly.Location
        Dim a As Integer = FileName.LastIndexOf("\")
        Dim b As Integer = FileName.LastIndexOf(".")
        Dim Result As String
        If b > a And a > 0 And b - a - 1 Then
            Result = FileName.Substring(a + 1, b - a - 1)
            Return Result
        Else
            Return ""
        End If
    End Function
    ''' <summary>
    ''' 获取文件名后缀类型
    ''' </summary>
    ''' <param name="FileName"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getOnlyType(ByVal FileName As String) As String
        Dim a As Integer = FileName.LastIndexOf(".")
        Dim b As Integer = FileName.LastIndexOf("\")
        If a > b And a > 0 Then
            Return FileName.Substring(a + 1).Trim
        Else
            Return ""
        End If
    End Function
    Public Function GetDeskTop() As String
        Dim tmp As String = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Return tmp
    End Function
    Public Function GetStartMenuPath() As String
        Dim tmp As String = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)
        Return tmp
    End Function
#End Region
#Region "查找替换内容翻译"
    Public Function TranslateText(ByVal Value As String) As String
        Dim a As Integer, b As Integer
        Dim tmp As String = Value
        Dim dWord As New ArrayList
        Do Until a < 0
            a = tmp.IndexOf("[")
            b = tmp.IndexOf("]")
            If b > a And a >= 0 Then
                Dim str1 As String = tmp.Substring(a, b - a + 1)
                dWord.Add(str1)
                tmp = tmp.Substring(b + 1)
            End If
        Loop
        Return ModifySpacChar(Value, dWord)
    End Function
    Private Function ModifySpacChar(ByVal OldString As String, ByVal dWord As ArrayList) As String
        If dWord IsNot Nothing Then
            If dWord.Count > 0 Then
                For i = 0 To dWord.Count - 1
                    Dim tmp As String = dWord.Item(i).ToString.Replace("[", "").Replace("]", "")
                    Dim a As Integer = tmp.IndexOf(":")
                    Dim Str1, Str2 As String
                    If a > 0 Then
                        Str1 = tmp.Substring(0, a) : Str2 = tmp.Substring(a + 1)
                        If Str1.ToLower = "asc" And IsNumeric(Str2) Then
                            OldString = OldString.Replace(dWord.Item(i).ToString, Chr(Val(Str2)))
                        End If
                    End If
                Next
                Return OldString
            Else
                Return OldString
            End If
        Else
            Return OldString
        End If
    End Function
    Public Function getItemValue(ByVal Item As ListViewItem, ByVal Index As Integer) As String
        If Item IsNot Nothing Then
            If Index >= 0 And Index < Item.SubItems.Count Then
                Return Item.SubItems(Index).Text
            Else
                Return ""
            End If
        Else
            Return ""
        End If
    End Function
    Public Sub SetItemValue(ByVal Item As ListViewItem, ByVal Index As Integer, ByVal Value As String)
        If Item IsNot Nothing Then
            If Index >= 0 And Index < Item.SubItems.Count Then
                Item.SubItems(Index).Text = Value
            Else
                For i = Item.SubItems.Count To Index Step 1
                    Item.SubItems.Add("")
                Next
                Item.SubItems.Item(Index).Text = Value
            End If
        End If
    End Sub
    Public Function getColorBlendByColors(ByVal Value As Color()) As ColorBlend
        Try
            Dim Result As New ColorBlend
            Dim p() As Single = Nothing
            If Value Is Nothing Then Return Nothing
            If Value.Length <= 0 Then Return Nothing
            For i = 0 To Value.Length - 1
                ReDim Preserve p(i)
                p(i) = i / (Value.Length - 1)
            Next
            Result.Colors = Value
            Result.Positions = p
            Return Result
        Catch
            Return Nothing
        End Try
    End Function
#End Region
End Module
